import 'package:flutter/cupertino.dart';
import 'package:riki_login/api/base_api.dart';
import 'package:riki_login/entity/send_sms_entity.dart';
import 'package:riki_login/entity/staff_login_entity.dart';
import 'package:riki_login/entity/user_login_entity.dart';

///作者：范玉辉
///创建时间：2021/8/17
///说明：

///发送验证码 (staff user)
class NetEaseSendSmsApi extends BaseApi<SendSmsEntity> {
  NetEaseSendSmsApi(BuildContext context) : super(context);

  Map<String, dynamic> params(String phone, String neCaptchaValidate, int smsType) {
    // neCaptchaValidate 网易返回
    // smsType  1, "客戶 端APP注册登录 2, "服务端APP登录 3, "服务端APP注册
    return {
      'phone': phone,
      'neCaptchaValidate': neCaptchaValidate,
      'smsType': smsType,
    };
  }

  @override
  HttpMethod get httpMethod => HttpMethod.post;

  @override
  String apiMethod(params) => 'app/sms/sendSms/v2';

  @override
  SendSmsEntity? onExtractResult(resultData, HttpData<SendSmsEntity> data) {
    return resultData != null ? SendSmsEntity.fromJson(resultData) : null;
  }
}

/// 验证码  校验验证码 (staff)
class SmsStaffCheckCodeApi extends BaseApi<StaffLoginEntity> {
  final String phone;
  final String code;

  SmsStaffCheckCodeApi(BuildContext context, this.phone, this.code) : super(context);

  @override
  HttpMethod get httpMethod => HttpMethod.post;

  @override
  String apiMethod(params) => 'app/sms/serverApp/checkCode';

  @override
  StaffLoginEntity? onExtractResult(resultData, HttpData<StaffLoginEntity> data) {
    return resultData != null ? StaffLoginEntity.fromJson(resultData) : null;
  }
}

/// 验证码校验验证码 (User)
class SmsUserCheckCodeApi extends BaseApi<UserLoginEntity> {
  final String phone;
  final String code;
  SmsUserCheckCodeApi(BuildContext context, this.phone, this.code) : super(context);

  @override
  HttpMethod get httpMethod => HttpMethod.post;

  @override
  String apiMethod(params) => 'app/sms/checkCode';

  @override
  UserLoginEntity? onExtractResult(resultData, HttpData<UserLoginEntity> data) {
    return resultData != null ? UserLoginEntity.fromJson(resultData) : null;
  }
}
